/*
 Navicat Premium Data Transfer

 Source Server         : mysqlserver
 Source Server Type    : SQL Server
 Source Server Version : 16001000
 Source Host           : localhost\SQLEXPRESS:1433
 Source Catalog        : community
 Source Schema         : dbo

 Target Server Type    : SQL Server
 Target Server Version : 16001000
 File Encoding         : 65001

 Date: 20/04/2025 22:05:46
*/


-- ----------------------------
-- Table structure for __EFMigrationsHistory
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[__EFMigrationsHistory]') AND type IN ('U'))
	DROP TABLE [dbo].[__EFMigrationsHistory]
GO

CREATE TABLE [dbo].[__EFMigrationsHistory] (
  [MigrationId] nvarchar(150) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [ProductVersion] nvarchar(32) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[__EFMigrationsHistory] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Committee
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Committee]') AND type IN ('U'))
	DROP TABLE [dbo].[Committee]
GO

CREATE TABLE [dbo].[Committee] (
  [name] varchar(255) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [description] varchar(255) COLLATE Chinese_PRC_CI_AS  NULL,
  [createdAt] datetime  NULL,
  [contactPhone] varchar(255) COLLATE Chinese_PRC_CI_AS  NULL,
  [updatedAt] datetime  NULL,
  [address] varchar(255) COLLATE Chinese_PRC_CI_AS  NULL,
  [Id] int  IDENTITY(1,1) NOT NULL
)
GO

ALTER TABLE [dbo].[Committee] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for CommunityEvents
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[CommunityEvents]') AND type IN ('U'))
	DROP TABLE [dbo].[CommunityEvents]
GO

CREATE TABLE [dbo].[CommunityEvents] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [Title] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Description] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [StartTime] datetime2(7)  NOT NULL,
  [EndTime] datetime2(7)  NOT NULL,
  [Location] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [MaxParticipants] int  NOT NULL,
  [CreatedAt] datetime2(7)  NOT NULL,
  [UpdatedAt] datetime2(7)  NOT NULL
)
GO

ALTER TABLE [dbo].[CommunityEvents] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Complaints
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Complaints]') AND type IN ('U'))
	DROP TABLE [dbo].[Complaints]
GO

CREATE TABLE [dbo].[Complaints] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [UserId] int  NOT NULL,
  [Title] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Description] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [SubmittedAt] datetime2(7)  NOT NULL,
  [Status] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Response] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NULL,
  [ProcessedAt] datetime2(7)  NULL
)
GO

ALTER TABLE [dbo].[Complaints] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Complex
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Complex]') AND type IN ('U'))
	DROP TABLE [dbo].[Complex]
GO

CREATE TABLE [dbo].[Complex] (
  [Name] varchar(255) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Address] nvarchar(255) COLLATE Chinese_PRC_CI_AS  NULL,
  [Description] varchar(255) COLLATE Chinese_PRC_CI_AS  NULL,
  [CommitteeId] int  NULL,
  [CreatedAt] datetime  NULL,
  [UpdatedAt] datetime  NULL,
  [Id] int  IDENTITY(1,1) NOT NULL
)
GO

ALTER TABLE [dbo].[Complex] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for ComplexCommittee
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[ComplexCommittee]') AND type IN ('U'))
	DROP TABLE [dbo].[ComplexCommittee]
GO

CREATE TABLE [dbo].[ComplexCommittee] (
  [id] int  NOT NULL,
  [complexId] int  NULL,
  [committeeId] int  NULL
)
GO

ALTER TABLE [dbo].[ComplexCommittee] SET (LOCK_ESCALATION = TABLE)
GO

EXEC sp_addextendedproperty
'MS_Description', N'小区ID',
'SCHEMA', N'dbo',
'TABLE', N'ComplexCommittee',
'COLUMN', N'complexId'
GO

EXEC sp_addextendedproperty
'MS_Description', N'居委会ID',
'SCHEMA', N'dbo',
'TABLE', N'ComplexCommittee',
'COLUMN', N'committeeId'
GO


-- ----------------------------
-- Table structure for EventRegistrations
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[EventRegistrations]') AND type IN ('U'))
	DROP TABLE [dbo].[EventRegistrations]
GO

CREATE TABLE [dbo].[EventRegistrations] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [EventId] int  NOT NULL,
  [UserId] int  NOT NULL,
  [RegisteredAt] datetime2(7)  NOT NULL
)
GO

ALTER TABLE [dbo].[EventRegistrations] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for HouseComplex
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[HouseComplex]') AND type IN ('U'))
	DROP TABLE [dbo].[HouseComplex]
GO

CREATE TABLE [dbo].[HouseComplex] (
  [id] int  NOT NULL,
  [houseId] int  NOT NULL,
  [complexId] int  NOT NULL
)
GO

ALTER TABLE [dbo].[HouseComplex] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Houses
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Houses]') AND type IN ('U'))
	DROP TABLE [dbo].[Houses]
GO

CREATE TABLE [dbo].[Houses] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [BuildingNo] nvarchar(450) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [UnitNo] nvarchar(450) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [RoomNo] nvarchar(450) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [OwnerId] int  NULL,
  [Status] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Area] float(53)  NOT NULL,
  [CreatedAt] datetime2(7)  NOT NULL,
  [UpdatedAt] datetime2(7)  NOT NULL,
  [ComplexId] int  NULL
)
GO

ALTER TABLE [dbo].[Houses] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Permissions
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Permissions]') AND type IN ('U'))
	DROP TABLE [dbo].[Permissions]
GO

CREATE TABLE [dbo].[Permissions] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [Name] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Description] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL
)
GO

ALTER TABLE [dbo].[Permissions] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for PropertyEquipments
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[PropertyEquipments]') AND type IN ('U'))
	DROP TABLE [dbo].[PropertyEquipments]
GO

CREATE TABLE [dbo].[PropertyEquipments] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [Name] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Location] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [InstallDate] datetime2(7)  NOT NULL,
  [IsOperational] bit  NOT NULL,
  [CreatedAt] datetime2(7)  NOT NULL,
  [UpdatedAt] datetime2(7)  NOT NULL
)
GO

ALTER TABLE [dbo].[PropertyEquipments] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for PropertyFees
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[PropertyFees]') AND type IN ('U'))
	DROP TABLE [dbo].[PropertyFees]
GO

CREATE TABLE [dbo].[PropertyFees] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [HouseId] int  NOT NULL,
  [Amount] float(53)  NOT NULL,
  [DueDate] datetime2(7)  NOT NULL,
  [IsPaid] bit  NOT NULL,
  [CreatedAt] datetime2(7)  NOT NULL,
  [UpdatedAt] datetime2(7)  NOT NULL
)
GO

ALTER TABLE [dbo].[PropertyFees] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Residents
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Residents]') AND type IN ('U'))
	DROP TABLE [dbo].[Residents]
GO

CREATE TABLE [dbo].[Residents] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [Name] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Password] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Phone] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [IdCard] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Gender] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [BirthDate] datetime2(7)  NULL,
  [Address] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [HouseId] int  NULL,
  [CreatedAt] datetime2(7)  NOT NULL,
  [UpdatedAt] datetime2(7)  NOT NULL
)
GO

ALTER TABLE [dbo].[Residents] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Table structure for Users
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[Users]') AND type IN ('U'))
	DROP TABLE [dbo].[Users]
GO

CREATE TABLE [dbo].[Users] (
  [Id] int  IDENTITY(1,1) NOT NULL,
  [Username] nvarchar(450) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Password] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [FullName] nvarchar(max) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Email] nvarchar(450) COLLATE Chinese_PRC_CI_AS  NOT NULL,
  [Role] nvarchar(max) COLLATE Chinese_PRC_CI_AS DEFAULT N'User' NOT NULL,
  [CreatedAt] datetime2(7)  NOT NULL,
  [UpdatedAt] datetime2(7)  NOT NULL
)
GO

ALTER TABLE [dbo].[Users] SET (LOCK_ESCALATION = TABLE)
GO


-- ----------------------------
-- Primary Key structure for table __EFMigrationsHistory
-- ----------------------------
ALTER TABLE [dbo].[__EFMigrationsHistory] ADD CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY CLUSTERED ([MigrationId])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for Committee
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[Committee]', RESEED, 2)
GO


-- ----------------------------
-- Primary Key structure for table Committee
-- ----------------------------
ALTER TABLE [dbo].[Committee] ADD CONSTRAINT [PK__Committe__3214EC070DADD3D8] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for CommunityEvents
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[CommunityEvents]', RESEED, 6)
GO


-- ----------------------------
-- Primary Key structure for table CommunityEvents
-- ----------------------------
ALTER TABLE [dbo].[CommunityEvents] ADD CONSTRAINT [PK_CommunityEvents] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for Complaints
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[Complaints]', RESEED, 5)
GO


-- ----------------------------
-- Primary Key structure for table Complaints
-- ----------------------------
ALTER TABLE [dbo].[Complaints] ADD CONSTRAINT [PK_Complaints] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for Complex
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[Complex]', RESEED, 6)
GO


-- ----------------------------
-- Primary Key structure for table Complex
-- ----------------------------
ALTER TABLE [dbo].[Complex] ADD CONSTRAINT [PK__Complex__3214EC07578C17C7] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table ComplexCommittee
-- ----------------------------
ALTER TABLE [dbo].[ComplexCommittee] ADD CONSTRAINT [PK__ComplexC__3213E83FAA7E45EB] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for EventRegistrations
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[EventRegistrations]', RESEED, 5)
GO


-- ----------------------------
-- Indexes structure for table EventRegistrations
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [IX_EventRegistrations_EventId_UserId]
ON [dbo].[EventRegistrations] (
  [EventId] ASC,
  [UserId] ASC
)
GO


-- ----------------------------
-- Primary Key structure for table EventRegistrations
-- ----------------------------
ALTER TABLE [dbo].[EventRegistrations] ADD CONSTRAINT [PK_EventRegistrations] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Primary Key structure for table HouseComplex
-- ----------------------------
ALTER TABLE [dbo].[HouseComplex] ADD CONSTRAINT [PK__HouseCom__3213E83F6FEEACA8] PRIMARY KEY CLUSTERED ([id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for Houses
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[Houses]', RESEED, 6)
GO


-- ----------------------------
-- Indexes structure for table Houses
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [IX_Houses_BuildingNo_UnitNo_RoomNo]
ON [dbo].[Houses] (
  [BuildingNo] ASC,
  [UnitNo] ASC,
  [RoomNo] ASC
)
GO


-- ----------------------------
-- Primary Key structure for table Houses
-- ----------------------------
ALTER TABLE [dbo].[Houses] ADD CONSTRAINT [PK_Houses] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for Permissions
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[Permissions]', RESEED, 5)
GO


-- ----------------------------
-- Primary Key structure for table Permissions
-- ----------------------------
ALTER TABLE [dbo].[Permissions] ADD CONSTRAINT [PK_Permissions] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for PropertyEquipments
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[PropertyEquipments]', RESEED, 7)
GO


-- ----------------------------
-- Primary Key structure for table PropertyEquipments
-- ----------------------------
ALTER TABLE [dbo].[PropertyEquipments] ADD CONSTRAINT [PK_PropertyEquipments] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for PropertyFees
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[PropertyFees]', RESEED, 7)
GO


-- ----------------------------
-- Primary Key structure for table PropertyFees
-- ----------------------------
ALTER TABLE [dbo].[PropertyFees] ADD CONSTRAINT [PK_PropertyFees] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for Residents
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[Residents]', RESEED, 10)
GO


-- ----------------------------
-- Primary Key structure for table Residents
-- ----------------------------
ALTER TABLE [dbo].[Residents] ADD CONSTRAINT [PK_Residents] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO


-- ----------------------------
-- Auto increment value for Users
-- ----------------------------
DBCC CHECKIDENT ('[dbo].[Users]', RESEED, 9)
GO


-- ----------------------------
-- Indexes structure for table Users
-- ----------------------------
CREATE UNIQUE NONCLUSTERED INDEX [IX_Users_Email]
ON [dbo].[Users] (
  [Email] ASC
)
GO

CREATE UNIQUE NONCLUSTERED INDEX [IX_Users_Username]
ON [dbo].[Users] (
  [Username] ASC
)
GO


-- ----------------------------
-- Primary Key structure for table Users
-- ----------------------------
ALTER TABLE [dbo].[Users] ADD CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED ([Id])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)  
ON [PRIMARY]
GO

